
#pragma once

#define CARD_Club		0
#define CARD_Diamand	1
#define CARD_Heart		2
#define CARD_Spade		3
#define CARD_A			1
#define CARD_K			13
#define CARD_Q			12
#define CARD_J			11

#ifdef _USE_CARDS_DLL_
typedef bool(WINAPI* PFN_cdtInit)(LPINT lpNormalWidth, LPINT lpNormalHeight);
typedef void(WINAPI* PFN_cdtTerm)();
typedef bool(WINAPI* PFN_cdtDrawExt)(HDC hDC, int nXDest, int nYDest, int nActualWidth, int nActualHeight, 
	int nIndexOfCard, DWORD dwDrawingOption, COLORREF crBackColor);

#define CRADOption_Sharp		0x80000000
#define CRADOption_Card			0x0
#define CRADOption_Back			0x1
#define CRADOption_InvertCard	0x2
#define CRADOption_FillAndPlan	0x3		//Fill SRCAND PlanBack
#define CRADOption_Fill			0x4
#define CRADOption_PlanBack		0x5		//SRCAND PlanBack
#define CRADOption_CrossBack	0x6
#define CRADOption_CircleBack	0x7

class CCardsDLL
{
public:
	CCardsDLL();
	~CCardsDLL();

	bool init();
	__forceinline int getWidth(){ return cardWidth; }
	__forceinline int getHeight(){ return cardHeight; }
	__forceinline static int CardIndex(int color/*0-3*/, int point/*1-13*/) { return ((max(1, min(point, 13)) - 1) << 2) | (color & 0x3); }
	bool drawCard(HDC hDC, int nXDest, int nYDest, int nActualWidth, int nActualHeight, int color, int point, bool sharp = false);
	bool drawCardInvert(HDC hDC, int nXDest, int nYDest, int nActualWidth, int nActualHeight, int color, int point, bool sharp = false);
	bool drawBack(HDC hDC, int nXDest, int nYDest, int nActualWidth, int nActualHeight, int back/*0-11*/, bool sharp = false);
	bool fillCard(HDC hDC, int nXDest, int nYDest, int nActualWidth, int nActualHeight, COLORREF clr, bool sharp = false);
protected:
	HMODULE hLib;
	int initCount, cardWidth, cardHeight;
	PFN_cdtInit cdtInit;
	PFN_cdtTerm cdtTerm;
	PFN_cdtDrawExt cdtDrawExt;
};
#endif

class CCard : public CStatic
{
	DECLARE_DYNAMIC(CCard)

#ifdef _USE_CARDS_DLL_
public:
	CCard(CCardsDLL *dll, int color, int point, int back);
	bool SaveBmp(LPCWSTR fName, bool fore);
protected:
	CCardsDLL *m_pDLL;
#else
public:
	CCard(int color, int point, int back);
#endif
	virtual ~CCard();
#ifdef _USE_CARDS_DLL_
#endif

protected:
	DECLARE_MESSAGE_MAP()
	CBitmap *m_pForeNormal, *m_pBackNormal, *m_pFore, *m_pBack;
public:
	int mColor, mPoint, mBack, mWidth, mHeight;
	bool showFore;

	BOOL Create(CWnd* pParentWnd, DWORD dwStyle = WS_CHILD | WS_VISIBLE, UINT nID = 0xffff);
	void setSize(int width, int height, bool refresh = true);
	void setShowSide(bool fore, bool refresh = true);
	afx_msg void OnPaint();
	static LPCWSTR CardColorStr(int color);
	__forceinline LPCWSTR CardColorStr() { return CardColorStr(mColor); }
};
